package com.googlecode.gwtbb.client.only.remote.user;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.googlecode.gwtbb.client.only.GwtUtils;
import com.googlecode.gwtbb.client.only.glue.events.GwtbbEvents;
import com.googlecode.gwtbb.client.only.remote.ClientResponseEventCallback;
import com.googlecode.gwtbb.client.shared.remote.user.LoginResponse;
import com.googlecode.gwtbb.client.shared.remote.user.LoginUserBean;
import com.googlecode.gwtbb.client.shared.remote.user.RegisterResponse;
import com.googlecode.gwtbb.client.shared.remote.user.RegisterUserBean;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Jun 25, 2008
 */
public class UserServiceProxy implements UserServiceAsync {
	private static final UserServiceProxy instance = new UserServiceProxy();

	UserServiceAsync real = (UserServiceAsync)GwtUtils.createProxy(GWT.create(UserService.class), "/gwtbbExporter/userService");

	public static UserServiceProxy instance() {
		return instance;
	}

	public void get(Long id, AsyncCallback async) {
		real.get(id, async);
	}

	public void login(LoginUserBean loginUserBean, AsyncCallback async) {
		real.login(loginUserBean, new ClientResponseEventCallback<LoginResponse>(async) {
			public void raiseEvent(LoginResponse serverResponse) {
				GwtbbEvents.instance().fireLoginUserEvent(serverResponse);
			}
		});
	}

	public void register(RegisterUserBean registerUserBean, AsyncCallback async) {
		real.register(registerUserBean, new ClientResponseEventCallback<RegisterResponse>(async) {
			public void raiseEvent(RegisterResponse serverResponse) {
				GwtbbEvents.instance().fireCreateUserEvent(serverResponse);
			}
		});
	}
}
